package com.zeng.jiudian.servlet.show;

import com.alibaba.fastjson.JSONObject;
import com.zeng.jiudian.bean.ShowModel;
import com.zeng.jiudian.service.ShowService;
import com.zeng.jiudian.service.impl.ShowServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author JJ_yo
 * @Date 2020/7/25 - 16:23
 */
@WebServlet("/back/show/add")
public class ShowAddServlet extends HttpServlet
{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf-8");

        String bigTitle = req.getParameter("bigTitle");
        String smallTitle = req.getParameter("smallTitle");
        String hotelMsg = req.getParameter("hotelMsg");
        String contentTop = req.getParameter("contentTop");
        String contentMid = req.getParameter("contentMid");
        String contentBottom = req.getParameter("contentBottom");
        String isShow = req.getParameter("isShow");
        String recommend = req.getParameter("recommend");

        ShowModel showModel = new ShowModel();
        showModel.setBigTitle(bigTitle);
        showModel.setSmallTitle(smallTitle);
        showModel.setHotelMsg(hotelMsg);
        showModel.setContentTop(contentTop);
        showModel.setContentMid(contentMid);
        showModel.setContentBottom(contentBottom);
        showModel.setIsShow(isShow == null ? 0 : Integer.parseInt(isShow));
        showModel.setRecommend(isShow == null ? 0 : Integer.parseInt(recommend));

        ShowService showService = new ShowServiceImpl();
        int count = showService.add(showModel);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("count", count);
        resp.getWriter().println(jsonObject);
    }
}
